package xiaoyang.interceptor;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import xiaoyang.Constants;
import xiaoyang.pojo.Backend_user;
import xiaoyang.pojo.Dev_user;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class SysInterceptor extends HandlerInterceptorAdapter {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response,Object handler) throws Exception {
        HttpSession session=request.getSession();
        Backend_user nn =(Backend_user) session.getAttribute(Constants.USER_SESSION);
        Dev_user dev_user= (Dev_user) session.getAttribute(Constants.DEV_USER_SESSION);
        String uri = request.getRequestURI();
        if (nn!=null){
            if (uri.indexOf("backappInfo")!=-1){
                return true;
            }else {
                response.sendRedirect(request.getContextPath()+"/403.jsp");
                return false;
            }
        }else if (dev_user!=null){
            if (uri.indexOf("appInfo")!=-1){
                return true;
            }else {
                response.sendRedirect(request.getContextPath()+"/403.jsp");
                return false;
            }
        }else{
            response.sendRedirect(request.getContextPath()+"/403.jsp");
            return false;
        }

    }
}
